package v1beta1

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

// DiskSpec defines the desired state of disk
type DiskSpec struct {
	//+optional
	OwnerId string `json:"ownerId,omitempty"`
	// provider secret
	ProviderRef ProviderRef `json:"providerRef,omitempty"`
	Size        int32       `json:"size,omitempty"`
	Count       int32       `json:"count,omitempty"`
	//TODO abstract VolumeType resource
	VolumeType string `json:"volumeType,omitempty"`
	// 是否为共享云硬盘。 true：表示为共享云硬盘。 false：表示为非共享云硬盘
	Multiattach bool `json:"multiattach,omitempty"`
	//+optional
	DataStore string `json:"dataStore,omitempty"`
	// 是否为可共享云硬盘。 说明： 该字段已经废弃，请使用multiattach。
	Shareable        bool             `json:"shareable,omitempty"`
	ResourceAffinity ResourceAffinity `json:"resourceAffinity,omitempty"`
	//+optional
	VolumeId string `json:"volumeId,omitempty"`
	// +optional
	OrderInfo OrderInfo `json:"orderInfo,omitempty"`
}

type Tag struct {
	Key   string `json:"key,omitempty"`
	Value string `json:"value,omitempty"`
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// +kubebuilder:resource:shortName=disk
// +kubebuilder:subresource:status

// Disk is the Schema for the c API
type Disk struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`
	Spec              DiskSpec `json:"spec,omitempty"`
	// status of disk
	Status DiskStatus `json:"status,omitempty"`
}

type ProviderRef struct {
	Namespace string `json:"namespace,omitempty"`
	SecretRef string `json:"secretRef,omitempty"`
}

type DiskStatus struct {
	Conditions []DiskConditions `json:"conditions,omitempty"`
	Phase      DiskPhaseType    `json:"phase,omitempty"`
	// returned volume information
	Info VolumeInfo `json:"info,omitempty" protobuf:"bytes,5,opt,name=info"`
}

type DiskConditions struct {
	// Type of deployment condition.
	Type ConditionType `json:"type" protobuf:"bytes,1,opt,name=type,casttype=InstallationConditionType"`
	// The last time this condition was updated.
	LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty" protobuf:"bytes,6,opt,name=lastUpdateTime"`
	// The reason for the condition's last transition.
	Reason string `json:"reason,omitempty" protobuf:"bytes,4,opt,name=reason"`
	// A human readable message indicating details about the transition.
	Message string `json:"message,omitempty" protobuf:"bytes,5,opt,name=message"`
}

type ConditionType string

const (
	DiskConditionJob  ConditionType = "job"
	DiskConditionDisk ConditionType = "disk"
)

// job information of creating disk
type VolumeInfo struct {
	//+optinoal
	VolumeID string `json:"volumeids,omitempty"`
	//+optinoal
	VolumeName string `json:"volumeName,omitempty"`
	JobID      string `json:"jobid,omitempty"`
	//+optional
	orderID string `json:"orderid,omitempoty"`
}

type DiskConditionType string
type DiskPhaseType string

const (
	DiskRequestStatus DiskConditionType = "Requested"
	DiskReadyStatus   DiskConditionType = "Ready"
)

const (
	DiskCreatingPhase DiskPhaseType = "Creating"
	DiskReadyPhase    DiskPhaseType = "Ready"
	DiskFailedPhase   DiskPhaseType = "Failed"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// DiskList contains a list of disk item
type DiskList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []Disk `json:"items"`
}
